package com.atguigu.lease.common.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Created by 小可乐$ on 2024/8/12$ 14:30$
 * description:
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
//        自动填充创建时间
        this.strictInsertFill(metaObject,"createTime", Date.class,new Date());
//        自动创建逻辑删除默认值0
        this.strictInsertFill(metaObject,"isDeleted",Byte.class,(byte)0);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
//        自动填充修改时间
        this.strictUpdateFill(metaObject,"updateTime", Date.class,new Date());
    }
}
